//
//  OAAlertManager.m
//  OASDK_Works
//
//  Created by ChenJie on 5/10/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "OAAlertManager.h"
#import <UIKit/UIKit.h>

NSString *const ASAlertControllerTitleKey = @"ASAlertControllerTitleKey";
NSString *const ASAlertControllerStyleKey = @"ASAlertControllerStyleKey";
NSString *const ASAlertControllerHandlerKey = @"ASAlertControllerHandlerKey";

@implementation OAAlertManager

+ (void)alertWithTitle:(NSString *)title
               message:(NSString *)message
               actions:(NSArray<NSDictionary *> *)actions {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
                                                                             message:message
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    for (NSDictionary *actionInfo in actions) {
        NSString *title = actionInfo[ASAlertControllerTitleKey];
        UIAlertActionStyle style = [actionInfo[ASAlertControllerStyleKey] integerValue];
        void (^handler)(UIAlertAction *action) = actionInfo[ASAlertControllerHandlerKey];
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:title style:style handler:handler];
        [alertController addAction:action];
    }
    
    UIViewController *rootVc = [UIApplication sharedApplication].delegate.window.rootViewController;
    [rootVc presentViewController:alertController animated:YES completion:^{}];
    
}

@end
